package com.teama4.shop.service;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.teama4.shop.domain.*;
import com.teama4.shop.mapper.CommodityMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class CommodityServiceImpl implements CommodityService {
    @Autowired
    private CommodityMapper commodityMapper;


    @Override
    public long countByExample(CommodityExample example) {
        return commodityMapper.countByExample(example);
    }

    @Override
    public int deleteByExample(CommodityExample example) {
        return commodityMapper.deleteByExample(example);
    }

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return commodityMapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(Commodity record) {
        return commodityMapper.insert(record);
    }

    @Override
    public int insertSelective(Commodity record) {
        return commodityMapper.insertSelective(record);
    }

    @Override
    public List<Commodity> selectByExample(CommodityExample example) {
        return commodityMapper.selectByExample(example);
    }

    @Override
    public Commodity selectByPrimaryKey(Integer id) {
        return commodityMapper.selectByPrimaryKey(id);
    }

    @Override
    public int updateByExampleSelective(Commodity record, CommodityExample example) {
        return commodityMapper.updateByExampleSelective(record,example);
    }

    @Override
    public int updateByExample(Commodity record, CommodityExample example) {
        return commodityMapper.updateByExample(record,example);
    }

    @Override
    public int updateByPrimaryKeySelective(Commodity record) {
        return commodityMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(Commodity record) {
        return commodityMapper.updateByPrimaryKey(record);
    }


    @Override
    public List<CommoditySpecification> selectAllCommSpeByKey(Integer commodityId) {
        return commodityMapper.selectAllCommSpeByKey(commodityId);
    }

    @Override
    public CommoditySpecification selectAllCommSpeBySpecificationKey(Integer specificationId) {
        return commodityMapper.selectAllCommSpeBySpecificationKey(specificationId);
    }

    @Override
    public CommodityPaging selectByExample(CommodityExample example, int pageNum, int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        List<Commodity> commodities = commodityMapper.selectByExample(example);
        return new CommodityPaging(((Page)commodities).getTotal(),commodities);
    }


}
